//  Controller.h
//
//  Created by Ryan on Thu Sep 25 2003.
//  Chimoosoft (c) 2003 Chimoosoft. All rights reserved.
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.


#import <Cocoa/Cocoa.h>

@class StopWatch;
@class PreferenceController;
@class CMSTimeFormatter;
@class CMSSpeech;
@class Notifier;

@interface Controller : NSObject {
	BOOL alreadyAwoke;

	Notifier * notifier;
	
	NSSpeechRecognizer * speechRecognizer;
	CMSSpeech * speech;
	
	BOOL enableMini, enableMain, enableMulti, enableMenu;
	
	float multiplierFactor;

	IBOutlet id logDrawer;
	IBOutlet id logTextView;
	IBOutlet id logScrollView;
	
	IBOutlet id setCountDownWindow;
	IBOutlet id mainWindowProgressBar;
	
	NSUserDefaults * defaults;
	
	// Popup Menus
	IBOutlet id hMenu, mMenu, sMenu;	
	IBOutlet id hView, mView, sView;
	
	IBOutlet id upDownView;
	
	// Text Fields
	IBOutlet id readout;
	IBOutlet id multiplierField;
	
	// About Panel Related
	IBOutlet id aboutPanel;
	IBOutlet id mailToButton;
	
	// Windows
	IBOutlet id mainWindow;
	IBOutlet id miniWindow;
	IBOutlet id multiplierWindow;
	
	// Controllers
	IBOutlet id miniWindowController;
	PreferenceController * preferenceController;  //for the preference panel.
	
	// Toolbars
	NSToolbar * mainToolbar, * multiplierToolbar;
	
	// Other
	NSString * startStopText;
	
	// Sounds
	NSSound *secondTickSound, *minuteTickSound, *hourTickSound, *endSound;

	BOOL SRActive;  // is speech recognition active?
	
	// Timer specific stuff
	StopWatch * stopWatch;  //the actual StopWatch object

	int numBeepsLeft;		//how many beeps left to play?

	// Formatters
	CMSTimeFormatter * internalFormatter, * secTf;
	
	IBOutlet id sharedTimeFormatter;
	
	// Menu extra
	id statusBar;
	id statusItem;
	IBOutlet id menuExtra;
	
	BOOL countDownMode;
	BOOL inForeGround;
	BOOL musicWasPlaying;
	BOOL alreadyStoppedMusic;
	BOOL hasWarned;
	
	BOOL warnBeforeExpire;
	int warnBeforeExpireSeconds;

	BOOL speakTimeOnInterval;
	int intervalToSpeakSeconds;

	BOOL autoRepeatCountdown;
	float autoRepeatDelaySeconds;

	int lastSpokenTimeInterval;
	
	BOOL internalFontUpdate;
	
	double secDown;
}

- (float)currentRefreshRate;
- (void)updateSounds;

- (IBAction)menuChosen:(id)sender;
- (IBAction)elapsed:(id)sender;

- (IBAction)startStop:(id)sender;
- (IBAction)reset:(id)sender;

- (IBAction)hideMenuExtra:(id)sender;
- (IBAction)toggleMenuExtra:(id)sender;

- (IBAction)setDirectionUp:(id)sender;
- (IBAction)setDirectionDown:(id)sender;
- (void)handleCountDownExpired;

- (IBAction)logTime:(id)sender;
- (IBAction)clearLog:(id)sender;
- (IBAction)saveLog:(id)sender;

- (void)updateSounds;

- (IBAction)showSetCountdownWindow:(id)sender;

- (void)stopWatchDidStart:(StopWatch*)watch;
- (void)stopWatchDidStop:(StopWatch*)watch;	
- (void)stopWatchDidUpdate:(StopWatch*)watch;
- (void)stopWatchDidExpire:(StopWatch*)theWatch;
- (void)stopWatchDidTickSecond:(StopWatch*)theWatch;
- (void)stopWatchDidTickMinute:(StopWatch*)theWatch;
- (void)stopWatchDidTickHour:(StopWatch*)theWatch;
- (void)stopWatchDidReset:(StopWatch*)theWatch;

- (IBAction)toggleSpeechRecognition:(id)sender;

- (IBAction)toggleDirection:(id)sender;

- (IBAction)showAboutPanel:(id)sender;
- (IBAction)showPreferencePanel:(id)sender;

- (IBAction)showHideWindow:(id)sender;

- (IBAction)sendFeedback:(id)sender;
- (IBAction)openURLForTitle:(id)sender;
- (IBAction)openChimoosoftHome:(id)sender;

- (IBAction)closeThisWindow:(id)sender;
- (IBAction)donateWebPage:(id)sender;
- (IBAction)alreadyDonated:(id)sender;
- (IBAction)choosePresetStyle:(id)sender;
- (IBAction)countDownTimeAdjusted:(id)sender;


// Delegate methods for CMSVersioning.

- (NSURL*)productURL;

@end



// delegate methods
@interface Controller(NSApplicationNotifications)

- (void)applicationDidFinishLaunching:(NSNotification*)notification;
- (void)windowDidExpose:(NSNotification *)aNotification;

@end
